<template>
	<view class="address-container">
		<view class="address-choose-box" v-if="JSON.stringify(defaultAddress) === '{}' || JSON.stringify(defaultAddress) === undefined">
			<button type="primary" size="mini" class="btnChooseAddress" @click="chooseAddress">请选择收货地址+</button>
		</view>
		<view class="address-box" @click="gotoAddressManagement" v-else>
			<view class="address-left">
				<view class="address">
					<!-- 清城区 东城街道 广东南华工商职业学院 -->
					{{ defaultAddress.buyerAddr }}
				</view>
				<view class="buyer">
					<view class="buyer-name">
						{{ defaultAddress.buyerName }}
					</view>
					<view class="phone">
						{{ defaultAddress.phone }}
					</view>
				</view>
			</view>
			<view class="address-right">
				<uni-icons :size="20" type="forward"></uni-icons>
			</view>
		</view>
		<image src="/static/cart_border@2x.png" class="address-border"></image>
	</view>
</template>

<script>
	import { mapState, mapMutations, mapGetters } from 'vuex'
	export default {
		name:"my-address",
		data() {
			return {
				
			}
		},
		computed: {
			...mapState('module_user', ['address']),
			...mapGetters('module_user', ['addstr', 'defaultAddress']),
		},
		methods: {
			...mapMutations('module_user', ['updateAddress']),
			async chooseAddress() {
				// const res = await uni.chooseAddress().catch(err => err)	
				// if(res[1].errMsg === 'chooseAddress:ok') {
				// 	this.updateAddress(res[1])
				// }
				uni.navigateTo({
					url: '/subcontract/address_management/address_management'
				})
			},
			gotoAddressManagement() {
				uni.navigateTo({
					url: '/subcontract/address_management/address_management'
				})
			}
		}
	}
</script>

<style lang="scss">
.address-container {
	// padding: 30rpx 30rpx 0 30rpx;
	border-radius: 8rpx;
	box-sizing: border-box;
	background-color: #fff;
	overflow: hidden;
}

.address-border {
	display: block;
	width: 100%;
	height: 2px;
}

.address-choose-box {
	width: 100%;
	display: flex;
	align-items: center;
	padding: 30rpx;
	box-sizing: border-box;
	justify-content: center;
}
.address-box {
	padding: 30rpx;
	display: flex;
	box-sizing: border-box;
	justify-content: space-between;
	.address {
		font-size: 16px;
		font-weight: bold;
	}
	.buyer {
		margin-top: 20rpx;
		display: flex;
		font-size: 14px;
		.buyer-name {
			margin-right: 30rpx;
		}
	}
	.address-right {
		width: 20%;
		display: flex;
		align-items: center;
		justify-content: center;
	}
}
</style>